<template>
	<view :data-theme="themeStyle">
		<view class="container">
			<view class="member-container">
				<view class="member-bg">
					<view class="member-bg-circle" :data-theme="defaultInfo.topStyle == 'default' ? themeStyle : ''"
						:style="{left: (-3000+750)/2 + 'rpx'}">
						<view class="user-section ns-gradient-pages-member-index-index"
							:data-theme="defaultInfo.topStyle == 'default' ? themeStyle : ''"
							:style="{background: defaultInfo.topStyle != 'default' ? defaultInfo.bgColor : '', width: windowWidth+'px', left: (3000-750)/2 + 'rpx'}">
							<view class="bg-img">
								<image :src="defaultBgImg" mode="widthFix"></image>
							</view>
							<view class="user-section-box">
								<view class="user-info-box" v-if="token && memberInfo">
									<view @click="getWxAuth" class="user-head">
										<image
											:src="memberInfo.headimg ? $util.img(memberInfo.headimg) : $util.getDefaultImage().default_headimg"
											mode="aspectFill"
											@error="memberInfo.headimg = $util.getDefaultImage().default_headimg">
										</image>
									</view>

									<view class="user-box">
										<!-- #ifdef MP -->
										<block
											v-if="(memberInfo.nickname.indexOf('u_') != -1 && memberInfo.nickname == memberInfo.username) || memberInfo.nickname == memberInfo.mobile">
											<text class="user-title" :style="defaultTextColor"
												@click="getWxAuth">点击获取微信头像</text>
										</block>
										<block v-else>
											<text class="user-title" :style="defaultTextColor"
												@click="getWxAuth">{{ memberInfo.nickname }}</text>
											<view v-if="memberInfo.member_level_name"
												@click="redirectBeforeAuth('/otherpages/member/level/level')"
												class="user-label">
												<text>{{ memberInfo.member_level_name }}</text>
											</view>
										</block>
										<!-- #endif -->

										<!-- #ifdef H5 -->
										<block v-if="
												$util.isWeiXin() &&
													((memberInfo.nickname.indexOf('u_') != -1 && memberInfo.nickname == memberInfo.username) || memberInfo.nickname == memberInfo.mobile)
											">
											<text class="user-title" :style="defaultTextColor"
												@click="getWxAuth">点击获取微信头像</text>
										</block>
										<block v-else>
											<text class="user-title"
												:style="defaultTextColor">{{ memberInfo.nickname }}</text>
											<view v-if="memberInfo.member_level_name"
												@click="redirectBeforeAuth('/otherpages/member/level/level')"
												class="user-label">
												<text>{{ memberInfo.member_level_name }}</text>
											</view>
										</block>
										<!-- #endif -->

									</view>
								</view>
								<view class="user-info-box no-log" v-else
									@click="redirectBeforeAuth('/pages/member/index/index')">
									<view class="user-head">
										<image :src="$util.getDefaultImage().default_headimg"></image>
									</view>
									<view class="user-box">
										<text class="user-title" :style="defaultTextColor">{{ $lang('login') }}</text>
										<text class="user-desc"
											:style="defaultTextColor">{{ $lang('loginTpis') }}</text>
									</view>
								</view>
								<view @click="redirectBeforeAuth('/pages/member/info/info')" class="user-set"
									v-if="token">
									<view :style="defaultTextColor" class="iconfont iconshezhi"></view>
								</view>
								<view class="member-sction">
									<view class="sction-item"
										@click="redirectBeforeAuth('/otherpages/member/balance/balance')">
										<text class="num"
											:style="defaultTextColor">{{ memberInfo ? (parseFloat(memberInfo.balance) + parseFloat(memberInfo.balance_money)).toFixed(2) : '0.00' }}</text>
										<text class="sction-item-name"
											:style="defaultTextColor">{{ $lang('balance') }}</text>
									</view>
									<view class="line"></view>
									<view class="sction-item"
										@click="redirectBeforeAuth('/otherpages/member/point/point')">
										<text class="num"
											:style="defaultTextColor">{{ memberInfo ? parseInt(memberInfo.point) : '0'}}</text>
										<text class="sction-item-name"
											:style="defaultTextColor">{{ $lang('point') }}</text>
									</view>
									<view class="line"></view>
									<view class="sction-item"
										@click="redirectBeforeAuth('/otherpages/member/coupon/coupon')">
										<text class="num" :style="defaultTextColor">{{ couponNum }}</text>
										<text class="sction-item-name"
											:style="defaultTextColor">{{ $lang('coupon') }}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="member-body">
					<!-- 订单模块 -->
					<view class="order-section">
						<view class="order-head" @click="redirectBeforeAuth('/pages/order/list/list')">
							<text class="order-tit">{{ $lang('allOrders') }}</text>
							<view>
								<text class="order-tip">{{ $lang('seeAllOrders') }}</text>
								<text class="order-more iconfont iconright"></text>
							</view>
						</view>
						<view class="order-body">
							<view class="order-item"
								@click="redirectBeforeAuth('/pages/order/list/list?status=waitpay')">
								<view class="order-icon">
									<text v-if="orderNum.waitPay > 99" class="order-num color-base-bg">99+</text>
									<text v-else-if="orderNum.waitPay > 0"
										class="order-num color-base-bg">{{ orderNum.waitPay }}</text>
									<image :src="$util.img('upload/uniapp/member/index/order/default_order_1.png')"
										mode="aspectFit"></image>
								</view>
								<text class="order-name">{{ $lang('waitPay') }}</text>
							</view>
							<view class="order-item"
								@click="redirectBeforeAuth('/pages/order/list/list?status=waitsend')">
								<view class="order-icon">
									<text v-if="orderNum.readyDelivery > 99" class="order-num color-base-bg">99+</text>
									<text v-else-if="orderNum.readyDelivery > 0"
										class="order-num color-base-bg">{{ orderNum.readyDelivery }}</text>
									<image :src="$util.img('upload/uniapp/member/index/order/default_order_2.png')"
										mode="aspectFit"></image>
								</view>
								<text class="order-name">{{ $lang('readyDelivery') }}</text>
							</view>
							<view class="order-item"
								@click="redirectBeforeAuth('/pages/order/list/list?status=waitconfirm')">
								<view class="order-icon">
									<text v-if="orderNum.waitDelivery > 99" class="order-num color-base-bg">99+</text>
									<text v-else-if="orderNum.waitDelivery > 0"
										class="order-num color-base-bg">{{ orderNum.waitDelivery }}</text>
									<image :src="$util.img('upload/uniapp/member/index/order/default_order_3.png')"
										mode="aspectFit"></image>
								</view>
								<text class="order-name">{{ $lang('waitDelivery') }}</text>
							</view>
							<view class="order-item" @click="redirectBeforeAuth('/pages/order/activist/activist')">
								<view class="order-icon">
									<text v-if="orderNum.refunding > 99" class="order-num color-base-bg">99+</text>
									<text v-else-if="orderNum.refunding > 0"
										class="order-num color-base-bg">{{ orderNum.refunding }}</text>
									<image :src="$util.img('upload/uniapp/member/index/order/default_order_4.png')"
										mode="aspectFit"></image>
								</view>
								<text class="order-name">{{ $lang('refunding') }}</text>
							</view>
						</view>
					</view>

					<view class="Since-address" :style="backgroundUrl" v-if="is_community_address && token">
						<view class="Since-title">
							<text class="title">我的当前自提点</text>
							<view
								@click="redirectBeforeAuth('/otherpages/community/community_choose/community_choose?lat_old='+community_Info.latitude+'&log_old='+community_Info.longitude+'&name='+community_Info.community)">
								<text>切换自提点</text>
								<text class="iconfont iconright"></text>
							</view>
						</view>
						<view class="Since-box">
							<!-- <image :src="$util.img(community_Info.community_img)" mode="aspectFill"></image> -->
							<view class="Since-msg">
								<view class="name-box">
									<text class="Since-title-detail">{{community_Info.community}}</text>
									<text class="Since-status colorGray"
										v-if="community_Info.rest_status==1 && community_Info.status!=3">休息中</text>
									<text class="Since-status colorEed" v-if="community_Info.status==3">未营业</text>
								</view>

								<!--  -->
								<view class="Since-address-size" v-if="distance!=''">
									<text class="iconfont iconweizhi1"></text>距您{{distance}}
								</view>
							</view>
							<view class="Since-num">
								<view class="">粉丝数：<text>{{community_Info.team_count.data}}</text></view>
								<view class="">购买指数：<text>{{community_Info.order_sum}}</text></view>
							</view>
							<view class="Since-addredd-detail">地址:<text>{{community_Info.full_address}}</text></view>
							<view class="Since-info">
								<text class="iconfont iconbaozheng"></text>
								<text class="since-desc-1">如果您购买的商品有任何问题，请直接与购买的门店联系！门店将为您处理，</text>
								<text class="since-desc-2">让您售后无忧！</text>
							</view>
						</view>
					</view>

					<view class="Since-address Since-address-null" :style="backgroundUrl"
						v-if="!is_community_address || !token">
						<view class="Since-title">
							<text class="title">我的当前自提点</text>
							<view
								@click="redirectBeforeAuth('/otherpages/community/community_choose/community_choose')">
								<text>切换自提点</text>
								<text class="iconfont iconright"></text>
							</view>
						</view>
						<view class="Since-box">
							<!-- <image :src="$util.img('upload/uniapp/member/index/null.png')"></image> -->
							<view>您还未选择自提点哦~</view>
						</view>
					</view>

					<view class="help-body">
						<image :src="$util.img('upload/uniapp/member/index/phone.png')"></image>
						<text>帮帮忙热线</text>
						<view class="help-info">
							<view class="help-info-desc">如果您找不到购物的提货门店，</view>
							<view>
								<text class="help-info-action">请致电</text>
								<text class="iconfont icondianhua21" @click="tack_phone(telphone)"></text>
								<text class="help-info-phone" @click="tack_phone(telphone)">{{telphone}}</text>
							</view>
						</view>
					</view>

					<!-- 常用功能模块 -->
					<view class="example-body"
						:style="{ background: defaultInfo.topStyle == 'default' || defaultInfo.menuStyle == 'palace' ? '#fff' : '#f7f7f7' }">
						<view class="example-body-head"
							:class="{'example-tit-palace':defaultInfo.menuStyle != 'palace' && defaultInfo.topStyle != 'default'}">
							<text class="example-tit">常用工具</text>
						</view>
						<uni-grid :column="4" :show-border="false" :square="false"
							v-if="defaultInfo.menuStyle == 'palace' && defaultInfo.topStyle != 'default'">
							<block v-for="(item, index) in defaultInfo.menuList" :key="index">
								<view @click="redirectBeforeAuth(item.url)" v-if="menuIsShow(item)">
									<uni-grid-item>
										<image class="image" :src="$util.img(item.img)" mode="aspectFit" />
										<text class="text">{{ item.text }}</text>
									</uni-grid-item>
								</view>
							</block>
							<!-- <block v-if="is_community">
								<view @click="redirectBeforeAuth('/otherpages/community/community_leader')">
									<uni-grid-item>
										<image class="image" :src="$util.img('upload/uniapp/member/index/menu/icon7.png')" mode="aspectFit" />
										<text class="text">团长中心</text>
									</uni-grid-item>
								</view>
							</block> -->
							<block v-if="memberInfo.delivery_clerk_id>0">
								<view @click="redirectBeforeAuth('/otherpages/community/clerk_delivery')">
									<uni-grid-item>
										<image class="image"
											:src="$util.img('upload/uniapp/member/index/menu/icon8.png')"
											mode="aspectFit" />
										<text class="text">配送单</text>
									</uni-grid-item>
								</view>
							</block>
						</uni-grid>
						<uni-grid :column="4" :show-border="false" :square="false"
							v-if="defaultInfo.topStyle == 'default'">
							<block v-for="(list_item,list_index) in defaultInfo.menuList" :key="list_index">
								<view @click="redirectBeforeAuth(list_item.url)"
									v-if="list_item.url!='/otherpages/community/community_leader' && list_item.url!='/otherpages/community/clerk_delivery'">
									<uni-grid-item>
										<image class="image" :src="$util.img(list_item.img)" mode="aspectFit" />
										<text class="text">{{list_item.text}}</text>
									</uni-grid-item>
								</view>
								<view @click="redirectBeforeAuth('/otherpages/community/community_leader')"
									v-if="(is_community || is_community_leader ) && list_item.url=='/otherpages/community/community_leader'">
									<uni-grid-item>
										<image class="image" :src="$util.img(list_item.img)" mode="aspectFit" />
										<text class="text">{{list_item.text}}</text>
									</uni-grid-item>
								</view>
								<view
									v-if="memberInfo.delivery_clerk_id>0 && list_item.url=='/otherpages/community/clerk_delivery'"
									@click="redirectBeforeAuth(list_item.url)">
									<uni-grid-item>
										<image class="image" :src="$util.img(list_item.img)" mode="aspectFit" />
										<text class="text">{{list_item.text}}</text>
									</uni-grid-item>
								</view>
							</block>
						</uni-grid>

						<view v-if="defaultInfo.menuStyle != 'palace' && defaultInfo.topStyle != 'default'"
							class="list-style">
							<block v-for="(item, index) in defaultInfo.menuList" :key="index">
								<view class="list-style-item"
									:class="defaultInfo.insertGap == 0 ? 'no-interval' : 'interval'"
									@click="redirectBeforeAuth(item.url)" v-if="menuIsShow(item)">
									<image class="image" :src="$util.img(item.img)" mode="aspectFit" />
									<text class="text">{{ item.text }}</text>
									<text class="iconfont iconright"></text>
								</view>
							</block>
						</view>
					</view>

					<view class="padding-bottom">
						<ns-copy-right></ns-copy-right>
					</view>

					<!-- <view class="bottom_logo" v-if="copyrightLogo != ''">
						<image :src="$util.img('copyrightLogo')" @error="imgError()" mode="widthFix"></image>
					</view>
					<view class="bottom_logo" v-else>
						<image :src="$util.img('upload/uniapp/member/index/logo.png')" mode="widthFix"></image>
					</view> -->
					<view class="service-body">
						<view>
							<image :src="$util.img('upload/uniapp/member/index/icon1.png')" mode="aspectFit"></image>
							<text>便宜有好货</text>
						</view>
						<view>
							<image :src="$util.img('upload/uniapp/member/index/icon2.png')" mode="aspectFit"></image>
							<text>次日16:00自提</text>
						</view>
						<view>
							<image :src="$util.img('upload/uniapp/member/index/icon3.png')" mode="aspectFit"></image>
							<text>售后无忧</text>
						</view>
					</view>
				</view>

				<!-- <view class="padding-bottom">
					<ns-copy-right></ns-copy-right>
				</view> -->

				<ns-login ref="login"></ns-login>
				<loading-cover ref="loadingCover"></loading-cover>
				<!-- 底部tabBar -->
				<diy-bottom-nav type="shop" :class="{ hide: bottomNavHidden }"></diy-bottom-nav>
			</view>
		</view>
		<to-top v-if="showTop" @toTop="scrollToTopNative()"></to-top>

		<!-- 完善会员资料 -->
		<view @touchmove.prevent.stop class="member-complete-info-popup">
			<uni-popup ref="completeInfoPopup" type="bottom" :maskClick="false">
				<view class="complete-info-wrap">
					<view class="head">
						<text class="title">获取您的昵称、头像</text>
						<text class="color-tip tips">获取用户头像、昵称完善个人资料，主要用于向用户提供具有辨识度的用户中心界面</text>
						<text class="iconfont iconclose color-tip" @click="cancelCompleteInfo"></text>
					</view>
					<!-- #ifdef MP-WEIXIN -->
					<view class="item-wrap">
						<text class="label">头像</text>
						<button open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
							<image :src="avatarUrl ? avatarUrl : $util.getDefaultImage().default_headimg"
								@error="avatarUrl = $util.getDefaultImage().default_headimg" mode="aspectFill"></image>
							<text class="iconfont iconright color-tip"></text>
						</button>
					</view>
					<view class="item-wrap">
						<text class="label">昵称</text>
						<input type="nickname" placeholder="请输入昵称" v-model="nickName" @blur="blurNickName" />
					</view>
					<!-- #endif -->
					<!-- #ifdef MP-ALIPAY -->
					<view class="item-wrap">
						<text class="label">头像</text>
						<button open-type="getAuthorize" scope="userInfo" @getAuthorize="aliappGetUserinfo"
							:plain="true" class="border-0">
							<image :src="avatarUrl ? avatarUrl : $util.getDefaultImage().default_headimg"
								@error="avatarUrl = $util.getDefaultImage().default_headimg" mode="aspectFill"></image>
							<text class="iconfont iconright color-tip"></text>
						</button>
					</view>
					<view class="item-wrap">
						<text class="label">昵称</text>
						<input type="nickname" placeholder="请输入昵称" v-model="nickName" @blur="blurNickName" />
					</view>
					<!-- #endif -->
					<button type="default" class="save-btn" @click="saveCompleteInfo" :disabled="isDisabled">保存</button>
				</view>
			</uni-popup>
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<!-- 小程序隐私协议 -->
		<privacy-popup ref="privacyPopup"></privacy-popup>
		<!-- #endif -->
	</view>
</template>

<script>
	import uniGrid from '@/components/uni-grid/uni-grid.vue';
	import uniGridItem from '@/components/uni-grid-item/uni-grid-item.vue';
	import diyBottomNav from '@/components/diy-bottom-nav/diy-bottom-nav.vue';
	import toTop from '@/components/toTop/toTop.vue';
	import scroll from '@/common/js/scroll-view.js';
	import nsCopyRight from '@/components/ns-copyright/ns-copyright.vue';
	import globalConfig from '@/common/js/golbalConfig.js';

	export default {
		components: {
			uniGrid,
			uniGridItem,
			diyBottomNav,
			toTop,
			nsCopyRight
		},
		data() {
			return {
				token: '',
				memberInfo: null,
				couponNum: 0,
				orderNum: {
					waitPay: 0, //待付款
					readyDelivery: 0, //待发货
					waitDelivery: 0, //待收货
					waitEvaluate: 0, // 待评价
					refunding: 0 // 退款中
				},
				isVerification: true,
				copyrightLoad: 0,
				copyrightLogo: '',
				bottom_info: {},
				authInfo: {
					is_verifier: false
				},

				shopTop: false,
				scrollTop: 0,
				shopConfig: null,
				promoterInfo: null,
				withdrawConfig: null,
				defaultInfo: {
					topStyle: 'default',
					bgColor: '#ff454f',
					textColor: '#fff',
					bgImg: '',
					menuList: [],
					insertGap: '0',
					menuStyle: 'palace',
					level: 1
				},
				signState: 1, // 签到是否开启
				evaluateConfig: {
					evaluate_audit: 1,
					evaluate_show: 0,
					evaluate_status: 1
				},
				is_community: false, //是否可以申请团长
				is_community_leader: false,
				community_type: 0,
				community_Info: {}, //团长信息
				is_community_address: false,
				lat: '',
				log: '',
				distance: '', //距离站点的距离
				telphone: '',

				avatarUrl: '', // 头像预览
				headImg: '', // 头像保存
				nickName: '',
				completeInfoCallback: null
			};
		},
		mixins: [scroll, globalConfig],
		computed: {
			storeToken() {
				return this.$store.state.token;
			},
			defaultBgColor() {
				var val = '';
				if (this.defaultInfo.topStyle != 'default') {
					val = 'background:' + this.defaultInfo.bgColor;
				}
				return val;
			},
			topStyle() {
				var val = '',
					_width = 0;
				if (this.defaultInfo.topStyle != 'default') {
					val = 'background:' + this.defaultInfo.bgColor;
				}

				uni.getSystemInfo({
					success: function(res) {
						_width = res.windowWidth;
					}
				});

				val += 'width:' + _width + 'px';
				val += 'left:' + (1500 - _width) / 2 + 'px';
				return val;
			},
			defaultBgImg() {
				var defaultImg = '';
				if (this.defaultInfo.topStyle != 'default') {
					defaultImg = this.defaultInfo.bgImg ? this.$util.img(this.defaultInfo.bgImg) : '';
				} else {
					defaultImg = this.$util.img('upload/uniapp/member/index/member_bg.png');
				}
				return defaultImg;
			},
			defaultTextColor() {
				var textColor = '';
				if (this.defaultInfo.topStyle != 'default') {
					textColor = 'color:' + this.defaultInfo.textColor + ' !important';
				}
				return textColor;
			},
			windowWidth() {
				let val = 0;
				uni.getSystemInfo({
					success: function(res) {
						val = res.windowWidth;
					}
				});
				return val;
			},
			backgroundUrl() {
				let url = this.$util.img('upload/uniapp/member/index/bg.png');
				var str = 'background:' + 'url(' + url + ') no-repeat 0 0/100%';
				return str;
			},
			isDisabled() {
				if (this.nickName.length > 0) return false;
				return true;
			}
		},
		watch: {
			storeToken: async function(nVal, oVal) {
				if (this.addonIsExit.membersignin) {
					await this.getSignState();
				}
				await this.getMemberInfo();
				this.getOrderNum();
				this.getCouponNum();
				this.checkIsVerifier();
			}
		},
		onLoad(data) {
			uni.hideTabBar();

			if (this.addonIsExit.memberwithdraw) {
				this.getWithdrawConfig();
			}
			this.getEvaluateConfig();
			this.getCopy();
			if (data.code) {
				this.$api.sendRequest({
					url: '/wechat/api/wechat/authcodetoopenid',
					data: {
						code: data.code
					},
					success: res => {
						if (res.code >= 0) {
							if (res.data.userinfo.nickName) this.modifyNickname(res.data.userinfo.nickName);
							if (res.data.userinfo.avatarUrl) this.modifyHeadimg(res.data.userinfo
								.avatarUrl);
						}
					}
				});
			}
		},
		async onReady() {
			if (this.addonIsExit.membersignin) {
				await this.getSignState();
			}
			await this.getDefaultInfo();
			if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
		},
		async onShow() {
			// 刷新多语言
			this.$langConfig.refresh();

			this.token = uni.getStorageSync('token');

			if (uni.getStorageSync('userInfo')) {
				this.memberInfo = uni.getStorageSync('userInfo');
			}
			this.getPhone();
			if (this.token) {
				if (this.addonIsExit.membersignin) {
					await this.getSignState();
				}
				await this.getMemberInfo();

				this.getOrderNum();
				this.getCouponNum();
				this.checkIsVerifier();

				this.lat = ''
				this.log = ''
				this.$util.getLocation().then(res=>{
					this.lat = res.latitude;
					this.log = res.longitude;
					this.getCommunity_info()
					this.getCommunity_qualification()
					this.getCommunity();
				})
			} else {
				this.initInfo();
			}
		},
		methods: {
			IPLoca() {
				this.$api.sendRequest({
					url: '/api/Address/ipLocation',
					success: res => {
						if (res.code >= 0) {
							console.log('IP定位成功')
							this.lat = res.data.location.lat
							this.log = res.data.location.lng
							this.getCommunity_info()
						}
					}
				});
			},
			//处理图片不存在的错误
			imgError() {
				this.copyrightLogo = 'upload/uniapp/member/index/logo.png'
			},
			getCopy() {
				this.$api.sendRequest({
					url: '/api/config/copyright',
					success: res => {
						if (res.code >= 0) {
							this.copyrightLogo = res.data.logo;
						}
					}
				});
			},
			// 单位转化
			conversion_util(e) {
				let _distance = e.distance
				let newDistance = ''
				if (_distance < 1) {
					newDistance = parseFloat(_distance) * 1000 + '米'
				} else {
					newDistance = _distance + '公里'
				}
				return newDistance
			},
			// 获取联系电话
			getPhone() {
				this.$api.sendRequest({
					url: '/api/config/contact',
					success: res => {
						if (res.code >= 0) {
							this.telphone = res.data.telephone;
						}
					}
				});
			},
			// 打电话
			tack_phone(e) {
				uni.makePhoneCall({
					phoneNumber: e
				});
			},
			// 签到是否开启
			async getSignState() {
				var res = await this.$api.sendRequest({
					url: '/api/membersignin/getSignStatus',
					async: false
				});
				if (res.code == 0) {
					this.signState = res.data.is_use;
				}
			},
			async getDefaultInfo() {
				var res = await this.$api.sendRequest({
					url: '/api/diyview/memberindex',
					async: false
				});
				if (res.code == 0) {
					this.defaultInfo.topStyle = res.data.topStyle;
					this.defaultInfo.bgColor = res.data.bgColor;
					this.defaultInfo.textColor = res.data.textColor;
					this.defaultInfo.bgImg = res.data.bgImg;
					this.defaultInfo.menuStyle = res.data.menuStyle;
					this.defaultInfo.menuList = res.data.menuList;
					this.defaultInfo.insertGap = res.data.insertGap;
					this.defaultInfo.level = res.data.level || 1;
				}
			},
			initInfo() {
				this.token = '';
				this.memberInfo = {
					balance: '0.00',
					balance_money: '0.00',
					point: 0
				};
				this.couponNum = 0;
				this.orderNum = {
					waitPay: 0, //待付款
					readyDelivery: 0, //待发货
					waitDelivery: 0, //待收货
					waitEvaluate: 0, // 待评价
					refunding: 0 // 退款中
				};
				this.authInfo = {
					is_verifier: false
				};
				uni.stopPullDownRefresh();
			},
			// 获取会员基础信息
			async getMemberInfo() {
				let res = await this.$api.sendRequest({
					url: '/api/member/info',
					async: false
				});
				if (res.code >= 0 && res.data) {
					this.token = uni.getStorageSync('token');
					this.memberInfo = res.data;

					this.headImg = this.memberInfo.headimg;
					this.nickName = this.memberInfo.nickname;
					this.avatarUrl = this.headImg ? this.$util.img(this.headImg) : this.$util
						.getDefaultImage().default_headimg;

					/*
						小程序用户头像昵称获取规则调整公告
						https://developers.weixin.qq.com/community/develop/doc/00022c683e8a80b29bed2142b56c01
						用于处理昵称将统一返回 “微信用户”
					*/
					if (this.nickName == '微信用户') {
						this.openCompleteInfoPop();
					}

					uni.setStorageSync('userInfo', this.memberInfo);
				} else {
					this.token = '';
					this.initInfo();
					uni.removeStorageSync('token');
					uni.removeStorageSync('userInfo');
				}
				// if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				uni.stopPullDownRefresh();
			},
			// 是否能开启申请团长
			getCommunity_qualification() {
				this.$api.sendRequest({
					url: '/api/community/config',
					data: {
						token: this.token
					},
					success: res => {
						if (res.code == 0) {
							if (res.data.value.is_allow_apply == 1) {
								// 可以申请
								this.is_community = true
							}
						}
					}
				});
			},
			// 团长信息
			getCommunity() {
				this.$api.sendRequest({
					url: '/api/community/getleaderinfo',
					data: {
						token: this.token
					},
					success: res => {
						if (res.code == 0) {
							if (res.data == null) {
								this.community_type = 4;
								this.is_community_leader = false;
							} else {
								this.is_community_leader = true;
								this.community_type = res.data.status
							}
						}
					}
				});
			},
			getCommunity_info() {
				this.$api.sendRequest({
					url: '/api/community/getMemberCommunity',
					data: {
						token: this.token,
						longitude: this.log,
						latitude: this.lat
					},
					success: res => {
						if (res.data) {
							this.is_community_address = true
							this.community_Info = res.data
							if (this.log && this.lat) {
								this.distance = this.conversion_util(this.community_Info)
							} else {
								this.distance = ''
							}
							// if (uni.getStorageSync('selfLocation')) {
							// 	let selfLocation = uni.getStorageSync('selfLocation')
							// 	if (this.community_Info.longitude) {
							// 		this.distance = this.$util.getDistance(selfLocation.latitude, selfLocation.longitude, this.community_Info
							// 			.latitude, this.community_Info.longitude);
							// 	}
							// } else {
							// 	this.distance = 0
							// }
							let fullAddress = res.data.full_address
							this.community_Info.full_address = fullAddress.replace(/,/g, '')
						} else {
							this.is_community_address = false
						}
					}
				});
			},
			// 下拉刷新
			onPullDownRefresh() {
				if (uni.getStorageSync('token')) this.getMemberInfo();
				else this.initInfo();
			},
			// 订单数量
			getOrderNum() {
				this.$api.sendRequest({
					url: '/api/order/num',
					data: {
						order_status: 'waitpay,waitsend,waitconfirm,waitrate,refunding'
					},
					success: res => {
						if (res.code == 0) {
							this.orderNum.waitPay = res.data.waitpay;
							this.orderNum.readyDelivery = res.data.waitsend;
							this.orderNum.waitDelivery = res.data.waitconfirm;
							this.orderNum.waitEvaluate = res.data.waitrate;
							this.orderNum.refunding = res.data.refunding;
						}
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			},
			// 优惠券数量
			getCouponNum() {
				this.$api.sendRequest({
					url: '/coupon/api/coupon/num',
					success: res => {
						if (res.code == 0) {
							this.couponNum = res.data;
						}
					}
				});
			},
			checkIsVerifier() {
				this.$api.sendRequest({
					url: '/api/verify/checkisverifier',
					success: res => {
						this.authInfo.is_verifier = (res.code == 0);
						this.$forceUpdate();
					}
				});
			},
			/**
			 * 获取余额提现配置
			 */
			getWithdrawConfig() {
				this.$api.sendRequest({
					url: '/api/memberwithdraw/config',
					success: res => {
						if (res.code >= 0 && res.data) {
							this.withdrawConfig = res.data;
							this.$forceUpdate();
						}
					}
				});
			},
			getEvaluateConfig() {
				this.$api.sendRequest({
					url: '/api/goodsevaluate/config',
					success: res => {
						if (res.code == 0) {
							var data = res.data;
							this.evaluateConfig = data;
						}
					}
				});
			},
			menuIsShow(data) {
				if(data.url == '/otherpages/community/community_leader'){
					return this.is_community || this.is_community_leader;
				}
				switch (data.tag) {
					case 'memberwithdraw':
						return this.withdrawConfig && this.withdrawConfig.is_use == 1;
						break;
					case 'membersignin':
						return this.signState == 1;
						break;
					case 'verifier':
						return this.authInfo.is_verifier;
						break;
					default:
						return true;
				}
				return true;
			},
			/**
			 * 修改昵称
			 * @param {Object} nickName
			 */
			modifyNickname(nickName) {
				this.$api.sendRequest({
					url: '/api/member/modifynickname',
					data: {
						nickname: nickName
					},
					success: res => {
						if (res.code == 0) this.memberInfo.nickname = nickName;
					}
				});
			},
			/**
			 * 修改头像
			 */
			modifyHeadimg(headimg) {
				this.$api.sendRequest({
					url: '/api/member/modifyheadimg',
					data: {
						headimg: headimg
					},
					success: res => {
						if (res.code == 0) this.memberInfo.headimg = headimg;
					}
				});
			},
			/**
			 * 跳转之前需先进行授权
			 * @param {Object} url
			 */
			redirectBeforeAuth(url) {
				if (!uni.getStorageSync('token')) {
					this.$refs.login.open('/pages/member/index/index');
					return;
				}

				if (url == '/otherpages/community/community_leader') {
					if (this.community_type == 2) {
						// 拒绝
						url = '/otherpages/community/community_apply_err';
					} else if (this.community_type == 0) {
						// 待审核
						url = '/otherpages/community/community_applying';
					} else if (this.community_type == 3) {
						// 被冻结
						url = '/otherpages/community/community_freeze';
					} else if (this.community_type == 4) {
						// 提交申请
						url = '/otherpages/community/community_apply';
					}
				}

				// #ifdef MP
				if ((this.memberInfo.nickname.indexOf('u_') != -1 && this.memberInfo.nickname == this.memberInfo
						.username) || this.memberInfo.nickname == this.memberInfo.mobile) {
					this.getWxAuth(() => {
						this.$util.redirectTo(url);
					});
				} else {
					this.$util.redirectTo(url);
				}
				// #endif

				// #ifdef H5
				if (
					this.$util.isWeiXin() &&
					((this.memberInfo.nickname.indexOf('u_') != -1 && this.memberInfo.nickname == this.memberInfo
						.username) || this.memberInfo.nickname == this.memberInfo.mobile)
				) {
					this.getWxAuth();
				} else {
					this.$util.redirectTo(url);
				}
				// #endif
			},
			/**
			 * 获取微信授权
			 */
			getWxAuth(callback) {
				// #ifdef MP
				this.openCompleteInfoPop(() => {
					typeof callback == 'function' && callback();
				});
				// #endif

				// #ifdef H5
				if (this.$util.isWeiXin()) {
					this.$api.sendRequest({
						url: '/wechat/api/wechat/authcode',
						data: {
							scopes: 'snsapi_userinfo',
							redirect_url: this.$config.h5Domain + '/pages/member/index/index'
						},
						success: res => {
							if (res.code >= 0) {
								location.href = res.data;
							}
						}
					});
				}
				// #endif
			},
			openCompleteInfoPop(callback) {
				this.$refs.completeInfoPopup.open(() => {
					this.$store.commit('setBottomNavHidden', false); //显示底部导航
				});
				this.$store.commit('setBottomNavHidden', true); // 隐藏底部导航
				this.completeInfoCallback = callback;
			},
			saveCompleteInfo() {
				if (this.nickName.length == 0) {
					this.$util.showToast({
						title: '请输入昵称'
					});
					return;
				}

				this.modifyNickname(this.nickName);
				this.modifyHeadimg(this.headImg);
				this.$refs.completeInfoPopup.close();
				this.$store.commit('setBottomNavHidden', false); // 显示底部导航
				typeof this.completeInfoCallback == 'function' && this.completeInfoCallback();
			},
			cancelCompleteInfo() {
				this.$refs.completeInfoPopup.close();
				this.$store.commit('setBottomNavHidden', false); // 显示底部导航
			},
			blurNickName(e) {
				if (e.detail.value) this.nickName = e.detail.value;
			},
			onChooseAvatar(e) {
				this.avatarUrl = e.detail.avatarUrl;
				uni.getFileSystemManager().readFile({
					filePath: this.avatarUrl, //选择图片返回的相对路径
					encoding: 'base64', //编码格式
					success: res => {
						let base64 = 'data:image/jpeg;base64,' + res.data; //不加上这串字符，在页面无法显示的哦

						this.$api.uploadBase64({
							base64,
							success: res => {
								if (res.code == 0) {
									this.headImg = res.data.pic_path;
								} else {
									this.$util.showToast({
										title: res.message
									});
								}
							},
							fail: () => {
								this.$util.showToast({
									title: '上传失败'
								});
							}
						})
					}
				});
			},
			// #ifdef MP-ALIPAY
			aliappGetUserinfo() {
				my.getOpenUserInfo({
					success: (res) => {
						let userInfo = JSON.parse(res.response).response
						if (userInfo.code && userInfo.code == '10000') {
							if (userInfo.avatar) {
								this.avatarUrl = userInfo.avatar;
								this.$api.pullImage({
									path: this.avatarUrl,
									success: res => {
										if (res.code == 0) {
											this.headImg = res.data.pic_path;
										} else {
											this.$util.showToast({
												title: res.message
											});
										}
									},
									fail: () => {
										this.$util.showToast({
											title: '头像拉取失败'
										});
									}
								})
							}
							this.nickName = userInfo.nickName
						} else {
							this.$util.showToast({
								title: userInfo.subMsg
							})
						}
					},
					fail: (err) => {
						this.$util.showToast({
							title: err.subMsg
						})
					}
				});
			}
			// #endif
		}
	};
</script>

<style lang="scss">
	@import '../public/css/index.scss';

	.hide {
		display: none;
	}

	/deep/.uni-scroll-view::-webkit-scrollbar {
		/* 隐藏滚动条，但依旧具备可以滚动的功能 */
		display: none
	}

	.member-complete-info-popup {
		.complete-info-wrap {
			background: #fff;
			padding: 50rpx 40rpx 40rpx;
			padding-bottom: calc(40rpx + constant(safe-area-inset-bottom));
			padding-bottom: calc(40rpx + env(safe-area-inset-bottom));

			.head {
				position: relative;
				border-bottom: 2rpx solid $color-line;
				padding-bottom: 20rpx;

				.title {
					font-size: $font-size-toolbar;
					display: block;
				}

				.tips {
					font-size: $font-size-base;
					display: block;
				}

				.iconfont {
					position: absolute;
					right: 0;
					top: -30rpx;
					display: inline-block;
					width: 56rpx;
					height: 56rpx;
					line-height: 56rpx;
					text-align: right;
					font-size: $font-size-toolbar;
					font-weight: bold;
				}
			}

			.item-wrap {
				border-bottom: 2rpx solid $color-line;
				display: flex;
				align-items: center;
				padding: 20rpx 0;

				.label {
					font-size: $font-size-toolbar;
					margin-right: 40rpx;
				}

				button {
					background: transparent;
					margin: 0;
					padding: 0;
					border-radius: 0;
					flex: 1;
					text-align: left;
					display: flex;
					align-items: center;
					font-size: $font-size-toolbar;
					border: none;

					image {
						width: 100rpx;
						height: 100rpx;
						border-radius: 10rpx;
						overflow: hidden;
					}
				}

				.iconfont {
					flex: 1;
					text-align: right;
				}

				input {
					flex: 1;
					height: 80rpx;
					box-sizing: border-box;
					font-size: $font-size-toolbar;
				}
			}

			.save-btn {
				width: 280rpx;
				height: 90rpx;
				line-height: 90rpx;
				background-color: #07c160;
				color: #fff;
				margin: 40rpx auto 20rpx;
			}
		}
	}
</style>
<style scoped>
	/deep/ .reward-popup .uni-popup__wrapper-box {
		background: none !important;
		max-width: unset !important;
		max-height: unset !important;
	}

	/deep/ .example-body .uni-grid-item text {
		font-size: 28rpx;
	}
</style>